App({
  onLaunch: function () {
    // 展示本地存储能力
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    this.screenSize();

    //运行环境
    const res = wx.getSystemInfoSync();
 //   console.log(res.AppPlatform)
    this.globalData.cj = res.AppPlatform
  },

  onHide() {
    // wx.removeStorageSync('nowSchool')
  },

  globalData: {
    userInfo: null,
   // host: 'https://49.235.39.125/a/data/', //测试
    host: 'https://bangbang.laigl.com/a/data/', //正式
   // host: 'https://10.4.85.95/a/data/',
    openid: '',
    token: '',
    uid: '',
    cj: '', //代码运行环境 默认空值微信 qq为‘qq’
    statusBarHeight: wx.getSystemInfoSync()['statusBarHeight']
  },

  //时间戳格式化
  dateFormat(timestamp, formats) {
    // formats格式包括
    // 1. Y-m-d
    // 2. Y-m-d H:i:s
    // 3. Y年m月d日
    // 4. Y年m月d日 H时i分
    formats = formats || 'Y-m-d';

    var zero = function (value) {
      if (value < 10) {
        return '0' + value;
      }
      return value;
    };

    var myDate = timestamp ? new Date(timestamp) : new Date();

    var year = myDate.getFullYear();
    var month = zero(myDate.getMonth() + 1);
    var day = zero(myDate.getDate());

    var hour = zero(myDate.getHours());
    var minite = zero(myDate.getMinutes());
    var second = zero(myDate.getSeconds());

    return formats.replace(/Y|m|d|H|i|s/ig, function (matches) {
      return ({
        Y: year,
        m: month,
        d: day,
        H: hour,
        i: minite,
        s: second
      })[matches];
    });
  },

  //飞入购物车效果函数
  //获取屏幕[宽、高]
  screenSize: function () {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.globalData.ww = res.windowWidth;
        that.globalData.hh = res.windowHeight;

      }
    })
  },
  /**
      * @param sx 起始点x坐标
      * @param sy 起始点y坐标
      * @param cx 控制点x坐标
      * @param cy 控制点y坐标
      * @param ex 结束点x坐标
      * @param ey 结束点y坐标
      * @param part 将起始点到控制点的线段分成的份数，数值越高，计算出的曲线越精确
      * @return 贝塞尔曲线坐标
     */
  bezier: function (points, part) {
    let sx = points[0]['x'];
    let sy = points[0]['y'];
    let cx = points[1]['x'];
    let cy = points[1]['y'];
    let ex = points[2]['x'];
    let ey = points[2]['y'];
    var bezier_points = [];
    // 起始点到控制点的x和y每次的增量
    var changeX1 = (cx - sx) / part;
    var changeY1 = (cy - sy) / part;
    // 控制点到结束点的x和y每次的增量
    var changeX2 = (ex - cx) / part;
    var changeY2 = (ey - cy) / part;
    //循环计算
    for (var i = 0; i <= part; i++) {
      // 计算两个动点的坐标
      var qx1 = sx + changeX1 * i;
      var qy1 = sy + changeY1 * i;
      var qx2 = cx + changeX2 * i;
      var qy2 = cy + changeY2 * i;
      // 计算得到此时的一个贝塞尔曲线上的点
      var lastX = qx1 + (qx2 - qx1) * i / part;
      var lastY = qy1 + (qy2 - qy1) * i / part;
      // 保存点坐标
      var point = {};
      point['x'] = lastX;
      point['y'] = lastY;
      bezier_points.push(point);
    }
    //console.log(bezier_points)
    return {
      'bezier_points': bezier_points
    };
  },





})
